package zozopo.manual;

import java.util.Map;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.SessionAware;

import zozopo.comm.Validate;
import zozopo.database.BusiDatabaseManager;
import zozopo.operations.comm.DictionaryOS;

import zozopo.user.operations.UserTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class PreviewAction extends ActionSupport implements Action ,SessionAware,ServletRequestAware{
	private static final Log logger = LogFactory.getLog(LogFactory.class);
	
	private Map<Object, Object> session;
	private String subject;
	private String lable;
	private String messageTemp;
	private String brand;
	public String getBrand() {
		return brand;
	}

	public void setBrand(String brand) {
		this.brand = brand;
	}
	HttpServletRequest request;
	
	public String execute(){
		
		DictionaryOS dictionaryOS = new DictionaryOS();
		
		lable = dictionaryOS.getDictValue(lable);
		//messageTemp = Validate.insertHtmlFilter(messageTemp);
		request.setAttribute("message", messageTemp);
		
		return SUCCESS;
	}
	
	public void validate() {
		UserTB user = (UserTB) session.get("userInfo"); 
		
		if(!user.getUser_state().equals("1")){
			addFieldError("errormessage", "用户未激活不能发布信息,请激活后再进行发布!");
			return;
		}
		
		if(lable == null || lable.trim().equals("")){
			lable="MANUAL.LABLE.OTHER";
		}
		
		if(subject.length() < 5){
			addFieldError("errormessage", "标题长度不能少于5个字符.请重新输入!");
			return;
		}
		
		
		//System.out.println(messageTemp);
	}
	
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}
	public String getLable() {
		return lable;
	}
	public void setLable(String lable) {
		this.lable = lable;
	}
	public String getMessageTemp() {
		return messageTemp;
	}
	public void setMessageTemp(String message) {
		this.messageTemp = message;
	}
	public String getSubmittype() {
		return submittype;
	}
	public void setSubmittype(String submittype) {
		this.submittype = submittype;
	}
	private String submittype;
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}

	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		request = arg0;
	}
}
